﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using WebProject.Core.Models;

namespace WebProject.Models
{
    public class NewsModel
    {
        public NewsModel()
        {
            
        }

        public NewsModel(News news)
        {
            Id = news.Id;
            Title = news.Title;
            Content = news.Content;
            Comment = news.Comment;
            CreateDate = news.CreateDate;
            NewsImageUrl = NewsImageUrl;
            IsDisplay = news.IsDisplay;
        }

        public int Id
        {
            get; set;
        }

        [Required(ErrorMessage = "{0}为必填项")]
        [StringLength(100, ErrorMessage = "{0}最长{1}个字符")]
        [DisplayName("标题")]
        public string Title
        {
            get;
            set;
        }

        [Required(ErrorMessage = "{0}为必填项")]
        [StringLength(1000, ErrorMessage = "{0}最长{1}个字符")]
        [DisplayName("新闻正文")]
        public string Content
        {
            get; set;
        }

        [StringLength(300, ErrorMessage = "{0}最长{1}个字符")]
        [DisplayName("备注")]
        public string Comment
        {
            get; set;
        }

        [Required(ErrorMessage = "{0}为必填项")]
        [DisplayName("创建日期")]
        public DateTime CreateDate
        {
            get; set;
        }

        [Required(ErrorMessage = "{0}为必填项")]
        [DisplayName("新闻插图路径")]
        public string NewsImageUrl
        {
            get; set;
        }

        [DisplayName("是否显示")]
        public bool IsDisplay
        {
            get; set;
        }

        public News ToNews()
        {
            return new News
                {
                    Comment = Comment,
                    CreateDate = CreateDate,
                    Content = Content,
                    Id = Id,
                    IsDisplay = IsDisplay,
                    NewsImageUrl = NewsImageUrl,
                    Title = Title
                };
        }
    }
}